package com.linkage.jz.bankruptcy.activity.Project.ZQUser;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.linkage.jz.bankruptcy.BankruptcyApp;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.activity.Main.CreateAddrActivity;
import com.linkage.jz.bankruptcy.activity.Project.EditProjectDetailActivity;
import com.linkage.jz.bankruptcy.activity.Project.ZQUser.DetailOper.ApplyChangerLegalRepActivity;
import com.linkage.jz.bankruptcy.adapter.FullyGridLayoutManager;
import com.linkage.jz.bankruptcy.base.BaseCreateActivity;
import com.linkage.jz.bankruptcy.bean.MyAddr;
import com.linkage.jz.bankruptcy.bean.TaskAtta;
import com.linkage.jz.bankruptcy.bean.ZQUserDetailBaseInfo;
import com.linkage.jz.bankruptcy.event.RefreshEvent;
import com.linkage.jz.bankruptcy.net.BaseSubscriber;
import com.linkage.jz.bankruptcy.net.Network;
import com.linkage.jz.bankruptcy.net.ToastUtil;
import com.linkage.jz.bankruptcy.widget.CommonPromptDialog;
import com.linkage.jz.bankruptcy.widget.PublicNoticeDialog;
import com.linkage.seapeak.pojo.UploadImage;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;


/**
 * @author AFAP
 * 债权人信息编辑
 */
public class EditZQUserBaseInfo_ChangeActivity extends BaseCreateActivity implements OnClickListener {
    private static final String TAG = EditZQUserBaseInfo_ChangeActivity.class.getSimpleName();
    private static final String ACTION_EDIT = "ACTION_EDIT";
    private static final String KEY_ZQUSER = "KEY_ZQUSER";
    private static final String KEY_TYPE = "KEY_TYPE";

    private int REQUEST_CODE_ADDRESS = 10001;

    private String sysAddressId = ""; //邮寄地址
    private MyAddr mAddrInfo;

    private String mAction = "";
    private ZQUserDetailBaseInfo mZQUserInfo;
    private ImageView top_back;
    // TODO
    private int opType = 0; //0:发送验证, 1:暂存
    private static int mType = 1; //0管理人，1债权人
    private static int mEdittype = 0; //0新增，1修改

    private static final int TYPE_BIG_JG = 0; //  0:机构债权人,1:自然债权人,2:税务
    private static final int TYPE_BIG_ZRR = 1;
    private static final int TYPE_BIG_SW = 2;
    private static final int TYPE_SMALL_FDDBR = 0; //0:法定代表人, 1:代理人 2:本人
    private static final int TYPE_SMALL_DLR = 1;
    private static final int TYPE_SMALL_BR = 2;
    private static final int TYPE_UPLOAD = 0; // 0:线上,1:线下
    private static final int TYPE_LOCAL = 1;

    private int identityBigTypes = TYPE_BIG_JG; // 身份大类
    private int identitySmallTypes = TYPE_SMALL_FDDBR; // 身份小类
    private int provideBusinessLicense = TYPE_UPLOAD; // 营业执照提供方式
    private int provideLegalRepresentative = TYPE_UPLOAD; // 法定代表人身份证明提供方式



    private EditText et_zqr_name, et_zg_dbr_othercontant,et_zg_dbr_email,et_zqr_dlr_name,et_zqr_dlr_mobile,et_zqr_dlr_mobile_other,et_zqr_dlr_email
            ,et_zqr_zrr_br_mobile,et_zqr_zrr_br_mobile_other,et_zqr_zrr_br_email,et_socialcode_id,et_taxchange_mobile_other,
            et_taxchange_email,et_zqr_fr_bankAccountName,et_zqr_fr_bank,et_zqr_fr_bankAccount,
            et_zg_dbr_name,et_zg_dbr_phone,et_zg_dbr_socialcode_id;
    private TextView tv_zqr_address,et_zg_dbr_cardid,et_socialcode_id_proxyer,et_zqr_dlr_sfz_zyz,et_zqr_zrr_br_card,et_taxchange_sfz_zyz;

    private View include_zqr_base_group_change,include_zqr_base_group_proxyer_change,include_zqr_zrr_br_change,include_tax_change;

    //    private static String mProID;
//    public static void start(Context context,MyProInfo info) {
//        Intent intent = new Intent(context, CreateProFlowActivity.class);
//        mInfo = info;
//        context.startActivity(intent);
//    }
    CommonPromptDialog mPromptDialog;

    public static void start(Context context, ZQUserDetailBaseInfo info, int cType, int edittype) {
        Intent intent = new Intent(context, EditZQUserBaseInfo_ChangeActivity.class);
        intent.putExtra(KEY_ZQUSER, info);
        intent.putExtra(KEY_TYPE, cType);
        mEdittype = edittype;
        context.startActivity(intent);
    }

    @Override
    public void setListener() {
    }

    @Override
    public void initTitle() {
    }

    @Override
    public void initView() {
    }

    @Override
    public void initData() {
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_edit_zqbase_user_change);
        super.onCreate(savedInstanceState);
        titlebar_title.setText("修改基础信息");

        mZQUserInfo = (ZQUserDetailBaseInfo) getIntent().getSerializableExtra(KEY_ZQUSER);
        mType = getIntent().getIntExtra(KEY_TYPE, 0);
        // 如果有了大类了，就认为是已经有了，进来编辑的


        initViews();

//        if (1 == mType) {
            titlebar_title.setText("修改基础信息");
            titlebar_menu_text.setText("完成");
//        }
        showTitle();
        titlebar_menu_text.setOnClickListener(this);

        mPromptDialog = new CommonPromptDialog(this, CommonPromptDialog.TYPE_TIPS);
        mPromptDialog.setContent("该操作须取得债权人授权或依据文件");
        mPromptDialog.setPositiveClickListener("已取得", view -> mPromptDialog.dismiss());
        mPromptDialog.setmCloseListener(v -> {
            mPromptDialog.dismiss();
            finish();
        });
        mPromptDialog.setNegativeClickListener("暂未取得", view -> {
            mPromptDialog.dismiss();
            finish();
        });
        if(mType==0) {
            mPromptDialog.show();
        }


    }


    //     mType = 1; //0管理人，1债权人
//     mEdittype = 0; //0新增，1修改
    private void showTitle() {

    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK && data != null) {
            if (requestCode == REQUEST_CODE_ADDRESS) {
                sysAddressId = data.getStringExtra("id");
                tv_zqr_address.setText(data.getStringExtra("desc"));
                mAddrInfo = (MyAddr) data.getSerializableExtra("bean");
            }
        }
    }

    // 法人身份证明文件
    private RecyclerView mImgRecyclerView_frsfzm;
    private List<UploadImage> mImgList_frsfzm = new ArrayList<>();
    private GridImagesAdapter mImgAdapter_frsfzm;


    // 营业执照
    private RecyclerView mImgRecyclerView_yyzz;
    private List<UploadImage> mImgList_yyzz = new ArrayList<>();
    private GridImagesAdapter mImgAdapter_yyzz;

    // 代理人身份证/执业证 （代理人）
    private RecyclerView mImgRecyclerView_dlr_sfz_zyz;
    private List<UploadImage> mImgList_dlr_sfz_zyz = new ArrayList<>();
    private GridImagesAdapter mImgAdapter_dlr_sfz_zyz;

    // 授权委托书 （代理人）
    private RecyclerView mImgRecyclerView_dlr_sqwt;
    private List<UploadImage> mImgList_dlr_sqwt = new ArrayList<>();
    private GridImagesAdapter mImgAdapter_dlr_sqwt;

    // 营业执照（代理人）
    private RecyclerView mImgRecyclerView_dlr_yyzz;
    private List<UploadImage> mImgList_dlr_yyzz = new ArrayList<>();
    private GridImagesAdapter mImgAdapter_dlr_yyzz;


    // 代理人身份证/执业证 （税务）
    private RecyclerView mImgRecyclerView_tax_sfz_zyz;
    private List<UploadImage> mImgList_tax_sfz_zyz = new ArrayList<>();
    private GridImagesAdapter mImgAdapter_tax_sfz_zyz;

    // 授权委托书 （税务）
    private RecyclerView mImgRecyclerView_tax_sqwt;
    private List<UploadImage> mImgList_tax_sqwt = new ArrayList<>();
    private GridImagesAdapter mImgAdapter_tax_sqwt;


    //身份证（自然人）
    private RecyclerView mImgRecyclerView_zrr_br_sfz;
    private List<UploadImage> mImgList_zrr_br_sfz = new ArrayList<>();
    private GridImagesAdapter mImgAdapter_zrr_br_sfz;


    private void initViews() {
//        titlebar_back.setOnClickListener(this);
        titlebar_menu_text.setText("完成");
        titlebar_menu_text.setVisibility(View.VISIBLE);

        top_back = findViewById(R.id.titlebar_back);
        top_back.setOnClickListener(this);

        include_zqr_base_group_change = findViewById(R.id.include_zqr_base_group_change);
        include_zqr_base_group_proxyer_change = findViewById(R.id.include_zqr_base_group_proxyer_change);
        include_zqr_zrr_br_change = findViewById(R.id.include_zqr_zrr_br_change);
        include_tax_change = findViewById(R.id.include_tax_change);

        et_zqr_name = findViewById(R.id.et_zqr_name);
        tv_zqr_address = findViewById(R.id.tv_zqr_address);
        et_zg_dbr_cardid = findViewById(R.id.et_zg_dbr_cardid);

        et_zg_dbr_othercontant = findViewById(R.id.et_zg_dbr_othercontant);
        et_zg_dbr_email = findViewById(R.id.et_zg_dbr_email);
        et_zqr_dlr_name = findViewById(R.id.et_zqr_dlr_name);

        et_zqr_dlr_mobile = findViewById(R.id.et_zqr_dlr_mobile);
        et_zqr_dlr_mobile_other = findViewById(R.id.et_zqr_dlr_mobile_other);
        et_zqr_dlr_email = findViewById(R.id.et_zqr_dlr_email);
        et_zqr_dlr_sfz_zyz = findViewById(R.id.et_zqr_dlr_sfz_zyz);
        et_zqr_zrr_br_mobile = findViewById(R.id.et_zqr_zrr_br_mobile);


        et_zqr_zrr_br_mobile_other = findViewById(R.id.et_zqr_zrr_br_mobile_other);
        et_zqr_zrr_br_email = findViewById(R.id.et_zqr_zrr_br_email);
        et_zqr_zrr_br_card = findViewById(R.id.et_zqr_zrr_br_card);
        et_socialcode_id = findViewById(R.id.et_socialcode_id);
        et_taxchange_mobile_other = findViewById(R.id.et_taxchange_mobile_other);
        et_taxchange_email = findViewById(R.id.et_taxchange_email);
        et_taxchange_sfz_zyz = findViewById(R.id.et_taxchange_sfz_zyz);
        et_zqr_fr_bankAccountName = findViewById(R.id.et_zqr_fr_bankAccountName);
        et_socialcode_id_proxyer =findViewById(R.id.et_socialcode_id_proxyer);

        et_zqr_fr_bank = findViewById(R.id.et_zqr_fr_bank);
        et_zqr_fr_bankAccount = findViewById(R.id.et_zqr_fr_bankAccount);


        if(mZQUserInfo.getIdentityBigTypes()== null)
        {
            return;
        }

        int bigType = Integer.parseInt(mZQUserInfo.getIdentityBigTypes().getValue());
        et_zqr_name.setText(mZQUserInfo.getCreditorName());
        et_zqr_name.setEnabled(false);


        mImgRecyclerView_frsfzm = findViewById(R.id.recycler_imgs_frsfzm);
        mImgRecyclerView_frsfzm.setLayoutManager(new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL,
                false));
        mImgAdapter_frsfzm = new BaseCreateActivity.GridImagesAdapter(this, TYPE_PREVIEW);
        mImgAdapter_frsfzm.setList(mImgList_frsfzm);
        mImgRecyclerView_frsfzm.setAdapter(mImgAdapter_frsfzm);

//        mImgRecyclerView_frsfzm.setEnable(false);


        mImgRecyclerView_yyzz= findViewById(R.id.recycler_imgs_yyzz);
        mImgRecyclerView_yyzz.setLayoutManager(new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL,
                false));
        mImgAdapter_yyzz = new BaseCreateActivity.GridImagesAdapter(this, TYPE_PREVIEW);
        mImgAdapter_yyzz.setList(mImgList_yyzz);
        mImgRecyclerView_yyzz.setAdapter(mImgAdapter_yyzz);


        mImgRecyclerView_dlr_sfz_zyz= findViewById(R.id.recycler_imgs_dlr_sfz_zyz);
        mImgRecyclerView_dlr_sfz_zyz.setLayoutManager(new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL,
                false));
        mImgAdapter_dlr_sfz_zyz = new BaseCreateActivity.GridImagesAdapter(this, TYPE_PREVIEW);
        mImgAdapter_dlr_sfz_zyz.setList(mImgList_dlr_sfz_zyz);
        mImgRecyclerView_dlr_sfz_zyz.setAdapter(mImgAdapter_dlr_sfz_zyz);

        mImgRecyclerView_dlr_sqwt= findViewById(R.id.recycler_imgs_dlr_sqwt);
        mImgRecyclerView_dlr_sqwt.setLayoutManager(new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL,
                false));
        mImgAdapter_dlr_sqwt = new BaseCreateActivity.GridImagesAdapter(this, TYPE_PREVIEW);
        mImgAdapter_dlr_sqwt.setList(mImgList_dlr_sqwt);
        mImgRecyclerView_dlr_sqwt.setAdapter(mImgAdapter_dlr_sqwt);


        mImgRecyclerView_dlr_yyzz= findViewById(R.id.recycler_imgs_dlr_yyzz);
        mImgRecyclerView_dlr_yyzz.setLayoutManager(new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL,
                false));
        mImgAdapter_dlr_yyzz = new BaseCreateActivity.GridImagesAdapter(this, TYPE_PREVIEW);
        mImgAdapter_dlr_yyzz.setList(mImgList_dlr_yyzz);
        mImgRecyclerView_dlr_yyzz.setAdapter(mImgAdapter_dlr_yyzz);


        mImgRecyclerView_tax_sfz_zyz= findViewById(R.id.recycler_imgs_tax_sfz_zyz);
        mImgRecyclerView_tax_sfz_zyz.setLayoutManager(new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL,
                false));
        mImgAdapter_tax_sfz_zyz = new BaseCreateActivity.GridImagesAdapter(this, TYPE_PREVIEW);
        mImgAdapter_tax_sfz_zyz.setList(mImgList_tax_sfz_zyz);
        mImgRecyclerView_tax_sfz_zyz.setAdapter(mImgAdapter_tax_sfz_zyz);

        mImgRecyclerView_tax_sqwt= findViewById(R.id.recycler_imgs_tax_sqwt);
        mImgRecyclerView_tax_sqwt.setLayoutManager(new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL,
                false));
        mImgAdapter_tax_sqwt = new BaseCreateActivity.GridImagesAdapter(this, TYPE_PREVIEW);
        mImgAdapter_tax_sqwt.setList(mImgList_tax_sqwt);
        mImgRecyclerView_tax_sqwt.setAdapter(mImgAdapter_tax_sqwt);


        mImgRecyclerView_zrr_br_sfz= findViewById(R.id.recycler_imgs_zrr_br_sfz);
        mImgRecyclerView_zrr_br_sfz.setLayoutManager(new FullyGridLayoutManager(this, 4, GridLayoutManager.VERTICAL,
                false));
        mImgAdapter_zrr_br_sfz = new BaseCreateActivity.GridImagesAdapter(this, TYPE_PREVIEW);
        mImgAdapter_zrr_br_sfz.setList(mImgList_zrr_br_sfz);
        mImgRecyclerView_zrr_br_sfz.setAdapter(mImgAdapter_zrr_br_sfz);


        et_zg_dbr_name  = findViewById(R.id.et_zg_dbr_name);
        et_zg_dbr_phone  = findViewById(R.id.et_zg_dbr_phone);
        et_zg_dbr_socialcode_id  = findViewById(R.id.et_zg_dbr_socialcode_id);

        if (bigType == 0) {
            int smallType = Integer.parseInt(mZQUserInfo.getIdentitySmallTypes().getValue());
            if(smallType == 0)
            {
                include_zqr_base_group_change.setVisibility(View.VISIBLE);
                et_zg_dbr_othercontant.setText(mZQUserInfo.getOtherContact());
                et_zg_dbr_email.setText(mZQUserInfo.getEmail());

                et_zg_dbr_cardid.setText(mZQUserInfo.getCardNumber());
                et_zg_dbr_cardid.setEnabled(false);
                et_zg_dbr_name.setText(mZQUserInfo.getLegalRepresentativeName());
                et_zg_dbr_name.setEnabled(false);
                et_zg_dbr_phone.setText(mZQUserInfo.getContact());
                et_zg_dbr_phone.setEnabled(false);
                et_zg_dbr_socialcode_id.setText(mZQUserInfo.getSocialUniformCreditCode());
                et_zg_dbr_socialcode_id.setEnabled(false);

                //法定代表人身份证
                if(mZQUserInfo.getProvideCardAttas()!=null) {
                    for (int i = 0; i < mZQUserInfo.getProvideCardAttas().size(); i++) {
                        TaskAtta atta = mZQUserInfo.getProvideCardAttas().get(i);
                        JSONObject obj = new JSONObject();
                        try {
                            obj.putOpt("filename", atta.getAttachmentName());
                            obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                            obj.putOpt("filesize", atta.getAttachmentSize());
                            obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                            mImgList_frsfzm.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
                //营业执照
                if(mZQUserInfo.getProvideBusinessLicenseAttas()!=null) {
                    for (int i = 0; i < mZQUserInfo.getProvideBusinessLicenseAttas().size(); i++) {
                        TaskAtta atta = mZQUserInfo.getProvideBusinessLicenseAttas().get(i);
                        JSONObject obj = new JSONObject();
                        try {
                            obj.putOpt("filename", atta.getAttachmentName());
                            obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                            obj.putOpt("filesize", atta.getAttachmentSize());
                            obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                            mImgList_yyzz.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }else{
                include_zqr_base_group_proxyer_change.setVisibility(View.VISIBLE);

                et_zqr_dlr_name.setText(mZQUserInfo.getAgentName());
                et_zqr_dlr_name.setEnabled(false);
                et_zqr_dlr_mobile.setText(mZQUserInfo.getContact());
                et_zqr_dlr_mobile.setEnabled(false);

                et_zqr_dlr_mobile_other.setText(mZQUserInfo.getOtherContact());
                et_zqr_dlr_email.setText(mZQUserInfo.getEmail());

                et_zqr_dlr_sfz_zyz.setText(mZQUserInfo.getCardNumber());
                et_zqr_dlr_sfz_zyz.setEnabled(false);

                et_socialcode_id_proxyer.setText(mZQUserInfo.getSocialUniformCreditCode());
                et_socialcode_id_proxyer.setEnabled(false);

                //代理人身份证/执业证
                if(mZQUserInfo.getCreditorsProvideCardAttas()!=null) {
                    for (int i = 0; i < mZQUserInfo.getCreditorsProvideCardAttas().size(); i++) {
                        TaskAtta atta = mZQUserInfo.getCreditorsProvideCardAttas().get(i);
                        JSONObject obj = new JSONObject();
                        try {
                            obj.putOpt("filename", atta.getAttachmentName());
                            obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                            obj.putOpt("filesize", atta.getAttachmentSize());
                            obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                            mImgList_dlr_sfz_zyz.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }

                //授权委托书
                if(mZQUserInfo.getProvidePowerAttorneyAttas()!=null) {
                    for (int i = 0; i < mZQUserInfo.getProvidePowerAttorneyAttas().size(); i++) {
                        TaskAtta atta = mZQUserInfo.getProvidePowerAttorneyAttas().get(i);
                        JSONObject obj = new JSONObject();
                        try {
                            obj.putOpt("filename", atta.getAttachmentName());
                            obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                            obj.putOpt("filesize", atta.getAttachmentSize());
                            obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                            mImgList_dlr_sqwt.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
                //营业执照
                if(mZQUserInfo.getProvideBusinessLicenseAttas()!=null) {
                    for (int i = 0; i < mZQUserInfo.getProvideBusinessLicenseAttas().size(); i++) {
                        TaskAtta atta = mZQUserInfo.getProvideBusinessLicenseAttas().get(i);
                        JSONObject obj = new JSONObject();
                        try {
                            obj.putOpt("filename", atta.getAttachmentName());
                            obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                            obj.putOpt("filesize", atta.getAttachmentSize());
                            obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                            mImgList_dlr_yyzz.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }

        if(bigType == 1)
        {
            int smallType = Integer.parseInt(mZQUserInfo.getIdentitySmallTypes().getValue());
            if(smallType == 2)
            {
                include_zqr_zrr_br_change.setVisibility(View.VISIBLE);

                //身份证
                //统一社会信用代码证

                if(mZQUserInfo.getProvideCardAttas()!=null) {
                    for (int i = 0; i < mZQUserInfo.getProvideCardAttas().size(); i++) {
                        TaskAtta atta = mZQUserInfo.getProvideCardAttas().get(i);
                        JSONObject obj = new JSONObject();
                        try {
                            obj.putOpt("filename", atta.getAttachmentName());
                            obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                            obj.putOpt("filesize", atta.getAttachmentSize());
                            obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                            mImgList_zrr_br_sfz.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
                et_zqr_zrr_br_mobile_other.setText(mZQUserInfo.getOtherContact());
                et_zqr_zrr_br_email.setText(mZQUserInfo.getEmail());
                et_zqr_zrr_br_card.setText(mZQUserInfo.getCardNumber());

            }else{
                include_zqr_base_group_proxyer_change.setVisibility(View.VISIBLE);
                et_zqr_dlr_name.setText(mZQUserInfo.getAgentName());
                et_zqr_dlr_name.setEnabled(false);
                et_zqr_dlr_mobile.setText(mZQUserInfo.getContact());
                et_zqr_dlr_mobile.setEnabled(false);

                et_zqr_dlr_mobile_other.setText(mZQUserInfo.getOtherContact());
                et_zqr_dlr_email.setText(mZQUserInfo.getEmail());

                et_zqr_dlr_sfz_zyz.setText(mZQUserInfo.getCardNumber());
                et_zqr_dlr_sfz_zyz.setEnabled(false);

                et_socialcode_id_proxyer.setText(mZQUserInfo.getSocialUniformCreditCode());
                et_socialcode_id_proxyer.setEnabled(false);

                //代理人身份证/执业证
                if(mZQUserInfo.getCreditorsProvideCardAttas()!=null) {
                    for (int i = 0; i < mZQUserInfo.getCreditorsProvideCardAttas().size(); i++) {
                        TaskAtta atta = mZQUserInfo.getCreditorsProvideCardAttas().get(i);
                        JSONObject obj = new JSONObject();
                        try {
                            obj.putOpt("filename", atta.getAttachmentName());
                            obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                            obj.putOpt("filesize", atta.getAttachmentSize());
                            obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                            mImgList_dlr_sfz_zyz.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }

                //授权委托书
                if(mZQUserInfo.getProvidePowerAttorneyAttas()!=null) {
                    for (int i = 0; i < mZQUserInfo.getProvidePowerAttorneyAttas().size(); i++) {
                        TaskAtta atta = mZQUserInfo.getProvidePowerAttorneyAttas().get(i);
                        JSONObject obj = new JSONObject();
                        try {
                            obj.putOpt("filename", atta.getAttachmentName());
                            obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                            obj.putOpt("filesize", atta.getAttachmentSize());
                            obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                            mImgList_dlr_sqwt.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
                //营业执照
                if(mZQUserInfo.getProvideBusinessLicenseAttas()!=null) {
                    for (int i = 0; i < mZQUserInfo.getProvideBusinessLicenseAttas().size(); i++) {
                        TaskAtta atta = mZQUserInfo.getProvideBusinessLicenseAttas().get(i);
                        JSONObject obj = new JSONObject();
                        try {
                            obj.putOpt("filename", atta.getAttachmentName());
                            obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                            obj.putOpt("filesize", atta.getAttachmentSize());
                            obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                            mImgList_dlr_yyzz.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }

        if(bigType == 2)
        {
            include_tax_change.setVisibility(View.VISIBLE);
            et_taxchange_mobile_other.setText(mZQUserInfo.getOtherContact());
            et_taxchange_email.setText(mZQUserInfo.getEmail());
            et_taxchange_sfz_zyz.setText(mZQUserInfo.getCardNumber());

            //代理人身份证/执业证
            if(mZQUserInfo.getCreditorsProvideCardAttas()!=null) {
                for (int i = 0; i < mZQUserInfo.getCreditorsProvideCardAttas().size(); i++) {
                    TaskAtta atta = mZQUserInfo.getCreditorsProvideCardAttas().get(i);
                    JSONObject obj = new JSONObject();
                    try {
                        obj.putOpt("filename", atta.getAttachmentName());
                        obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                        obj.putOpt("filesize", atta.getAttachmentSize());
                        obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                        mImgList_tax_sfz_zyz.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }

            //授权委托书
            if(mZQUserInfo.getProvidePowerAttorneyAttas()!=null) {
                for (int i = 0; i < mZQUserInfo.getProvidePowerAttorneyAttas().size(); i++) {
                    TaskAtta atta = mZQUserInfo.getProvidePowerAttorneyAttas().get(i);
                    JSONObject obj = new JSONObject();
                    try {
                        obj.putOpt("filename", atta.getAttachmentName());
                        obj.putOpt("filepath", atta.getAttachmentDownloadAddress());
                        obj.putOpt("filesize", atta.getAttachmentSize());
                        obj.putOpt("loadUrl", atta.getAttachmentPreviewAddress());
                        mImgList_tax_sqwt.add(new Gson().fromJson(obj.toString(), UploadImage.class));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }

        }


        et_zqr_fr_bankAccountName.setText(mZQUserInfo.getBankAccountName());
        et_zqr_fr_bank.setText(mZQUserInfo.getBank());
        et_zqr_fr_bankAccount.setText(mZQUserInfo.getBankAccount());

    }

    private UploadImage atta2img(TaskAtta atta) {
        UploadImage image = new UploadImage();
        image.setFilename(atta.getAttachmentName());
        image.setFilepath(atta.getAttachmentDownloadAddress());
        image.setFilesize(atta.getAttachmentSize());
        image.setLoadUrl(atta.getAttachmentPreviewAddress());
        return image;
    }



    public void saveData() {
        String email = "";
        String otherContact = "";
        String bankBranch = et_zqr_fr_bank.getText().toString();
        String bankAccountName = et_zqr_fr_bankAccountName.getText().toString();
        String bankAccount = et_zqr_fr_bankAccount.getText().toString();

        int bigType = Integer.parseInt(mZQUserInfo.getIdentityBigTypes().getValue());
        if (bigType == 0) {
            int smallType = Integer.parseInt(mZQUserInfo.getIdentitySmallTypes().getValue());
            if (smallType == 0) {
                otherContact = et_zg_dbr_othercontant.getText().toString();
                email = et_zg_dbr_email.getText().toString();

            } else {


                otherContact = et_zqr_dlr_mobile_other.getText().toString();
                email = et_zqr_dlr_email.getText().toString();

            }

        }

        if(bigType == 1) {
            int smallType = Integer.parseInt(mZQUserInfo.getIdentitySmallTypes().getValue());
            if (smallType == 2) {

                otherContact = et_zqr_zrr_br_mobile_other.getText().toString();
                email = et_zqr_zrr_br_email.getText().toString();
            } else {
                otherContact = et_zqr_dlr_mobile_other.getText().toString();
                email = et_zqr_dlr_email.getText().toString();
            }
        }

        if (bigType == 2) {
            otherContact = et_taxchange_mobile_other.getText().toString();
            email = et_taxchange_email.getText().toString();
        }

        mShapeLoadingDialog.setLoadingText("提交信息中...");
        mShapeLoadingDialog.setCanceledOnTouchOutside(false);
        mShapeLoadingDialog.show();

        Observable<JsonObject> observable;

        LinkedHashMap<String, String> parms = new LinkedHashMap<>();
        parms.put("userToken", getUserToken());
        parms.put("projectId", mZQUserInfo.getBankruptcyProjectId());
        parms.put("sysAddressId",sysAddressId);

        parms.put("creditorId",mZQUserInfo.getId());
        parms.put("email",email);
        parms.put("otherContact",otherContact);

        parms.put("bank",bankBranch);
        parms.put("bankBranch",bankBranch);
        parms.put("bankAccountName",bankAccountName);
        parms.put("bankAccount", bankAccount);
        parms.put("type", mType+"");


        Network.getAPIService()
                .editInfo(parms)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscriber<JsonObject>()
                {
                    @Override
                    public void onNext(JsonObject json) {
                        mShapeLoadingDialog.dismiss();
                        int code = json.get("code").getAsInt();
                        if (code != 0) {
                            super.onNext(json);
                            return;
                        }
                        RefreshEvent event = new RefreshEvent();
                        event.setType(RefreshEvent.TYPE_ZQR);
                        EventBus.getDefault().post(event);
                        ToastUtil.showShort("提交成功");
                        finish();
                    }

                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }

                    @Override
                    public void onError(Throwable e) {
                        mShapeLoadingDialog.dismiss();
                        super.onError(e);
                    }
                });
    }
    private PublicNoticeDialog noticeDialog;

    @Override
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()) {

            case R.id.tv_zqr_address:
                intent = new Intent(this, CreateAddrActivity.class);
                intent.putExtra(CreateAddrActivity.KEY_FROM, CreateAddrActivity.FROM_FLOW);
                if (mAddrInfo != null) {
                    intent.putExtra(CreateAddrActivity.KEY_BEAN, mAddrInfo);
                }
                startActivityForResult(intent, REQUEST_CODE_ADDRESS);
                break;
            case R.id.titlebar_back:
                finishpage();
                break;
            case R.id.titlebar_menu_text:
                saveData();
                break;
            default:
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {


        if (keyCode == KeyEvent.KEYCODE_BACK) {
            finishpage();
        }
        return super.onKeyDown(keyCode, event);
    }




    public void finishpage() {
        noticeDialog = new PublicNoticeDialog(EditZQUserBaseInfo_ChangeActivity.this, new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (v.getId() == R.id.btn_save_notice) {
                    EditZQUserBaseInfo_ChangeActivity.super.finish();
                }
                noticeDialog.dismiss();
            }
        }, 1, "提示", "放弃编辑？",
                "否", "是");
        noticeDialog.show();
    }

}

